package com.example.video.adapter

import android.widget.TextView
import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.base.entity.Reply
import com.example.base.entity.ReplyEntityItem
import com.example.video.R

class ReplyAdapter:BaseQuickAdapter<ReplyEntityItem,BaseViewHolder>(R.layout.item_reply) {
    override fun convert(holder: BaseViewHolder, item: ReplyEntityItem) {
        Glide.with(context).load(item.userlogo).error(R.drawable.ic_launcher_foreground).into(holder.getView(R.id.reply_image))
        holder.setText(R.id.reply_name,item.nickname)
        holder.setText(R.id.reply_time,item.createtime)
        holder.setText(R.id.reply_content,item.content)
        if(item.replyList!=null&& item.replyList.isNotEmpty()){

            holder.getView<TextView>(R.id.tv_more).isVisible = true
        }else{
            holder.getView<TextView>(R.id.tv_more).isVisible = false
        }
        //子评论内容
        val rv = holder.getView<RecyclerView>(R.id.reply_rv)
        val replyChildAdapter = ReplyChildAdapter()
        item.replyList?.let { replyChildAdapter.data.addAll(it) }
        rv.adapter = replyChildAdapter
        rv.layoutManager =LinearLayoutManager(context)

    }

}

class ReplyChildAdapter:BaseQuickAdapter<Reply,BaseViewHolder>(R.layout.item_repley_child) {
    override fun convert(holder: BaseViewHolder, item: Reply) {
        Glide.with(context).load(item.userlogo).error(R.drawable.ic_launcher_foreground).into(holder.getView(R.id.reply_image))
        holder.setText(R.id.reply_name,item.nickname)
        holder.setText(R.id.reply_time,item.createtime)
        holder.setText(R.id.reply_content,item.content)

    }

}

